package config

import (
	"encoding/json"
	"io/ioutil"
)

// GetDBConn 从配置文件获取数据库连接配置
func GetDBConn() (string, error) {
	content, err := ioutil.ReadFile("config.json")
	if err != nil {
		return "", err
	}
	configs := map[string]interface{}{}
	err = json.Unmarshal(content, &configs)
	if err != nil {
		return "", err
	}
	return configs["dbconn"].(string), nil
}

// GetHTTPBind 从配置文件获取http服务绑定地址和端口
func GetHTTPBind() (string, error) {
	content, err := ioutil.ReadFile("config.json")
	if err != nil {
		return "", err
	}
	configs := map[string]interface{}{}
	err = json.Unmarshal(content, &configs)
	if err != nil {
		return "", err
	}
	return configs["httpbind"].(string), nil
}

func GetTencentSecretKey() string {
	content, err := ioutil.ReadFile("config.json")
	if err != nil {
		return ""
	}
	configs := map[string]interface{}{}
	err = json.Unmarshal(content, &configs)
	if err != nil {
		return ""
	}
	return configs["tencent_api"].(map[string]interface{})["SecretKey"].(string)
}

func GetTencentSecretId() string {
	content, err := ioutil.ReadFile("config.json")
	if err != nil {
		return ""
	}
	configs := map[string]interface{}{}
	err = json.Unmarshal(content, &configs)
	if err != nil {
		return ""
	}
	return configs["tencent_api"].(map[string]interface{})["SecretId"].(string)
}
